package com.cloud.service.response;

/**
 * 返回结果统一处理
 *
 * @author qinxh
 * @date 2019/07/18
 */
public class ResultResponse<T>  {

    private String code;

    private String message;

    private T data;

    /** 如果json形式在Feign调用必须要显式实现无参的构造方法，否则会报解析报错。当然不过单纯作为一个springboot项目就不必要了*/
    public ResultResponse(){

    }

    public ResultResponse(String code, String message) {

        super();
        this.code = code;
        this.message = message;
    }

    public ResultResponse(String code, String message, T data) {

        super();
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功返回的结果
     *
     * @param data 返回数据对象
     * @return ResponseData
     */
    @SuppressWarnings("unchecked")
    public static ResultResponse ofSuccess(Object data) {

        return new ResultResponse("000000", "处理成功", data);
    }

    /**
     * 自定义返回结果
     *
     * @param code    返回自定义状态值
     * @param message 返回自定义字符串信息
     * @return ResponseData
     */
    public static ResultResponse ofMessage(String code, String message) {

        return new ResultResponse(code, message);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
